<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<?php

if($_GET['_a']==1)
{
	$id = $_GET['_d']; 
	
	$page = $_GET['page'];
	$st = $_REQUEST['_st'];
	$store = $_POST['store'];
	$url = $_POST['url'];
	$gad = $_POST['gad'];
	$make = $_POST['make'];
    $spec = mysql_escape_string($_POST['maincont']);
	$price = $_POST['price'];
	$flag = $_POST['flag'];
	$authorised = $_POST['status'];
	
	$q = mysql_fetch_array(mysql_query("select image  from  gadget_technology where id='".$_POST['hid']."'"));
	
	if($_FILES["upload"]["name"]=="")
	{
		 $file=$q['image'];	
	
	}
	
	if($_FILES["upload"]["name"]!="")
	{
		
	 $path ="../uploads/gadget_images/".$q["image"];
	  
	 @unlink($path);
	$file=gmdate('YmdHis').$_FILES["upload"]["name"] ;
     move_uploaded_file($_FILES["upload"]["tmp_name"],"../uploads/gadget_images/".$file);

	}
	
		
 mysql_query("update gadget_technology set store='$store', store_url='$url'
			, gadget='$gad'
			, make='$make'
			, specifications='$spec'
			, price='$price'
			, image='".$file."'
			, sale_flag	='$flag'
			,active_status='$authorised',
			modified_datetime=now() where id='$id'");
			
echo "<script>window.location='index.php?tc=gadgettech&_s=1';</script>";
}
$id = $_REQUEST['_d'];
$page = $_REQUEST['page'];
$st = $_REQUEST['st'];

if($_REQUEST['_s'] == 1)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Updated Successfully</div></td>
    </tr>    
    </table>
<?php } ?>


<?php
$st = $_REQUEST['st'];

$q = mysql_fetch_array(mysql_query("select * from  gadget_technology  where id='$id'"));

//$u = mysql_fetch_array(mysql_query("select * from users where Id='$q[UserId]'"));
?>



<form name="edgadgettech" action="index.php?tc=gadgettech_view&_d=<?php echo $id;?>&page=<?php echo $page;?>&_a=1&_st=<?php echo $st;?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="hid" value="<?php echo $q["id"];?>" />
<table width="99%" align="center" border="0"  class="list" cellpadding="5">
<thead>

<tr>
	<td colspan="3" align="left">
        <div style="float:left">Gadget</div>
        <div style="float:right"><a href="index.php?tc=gadgettech&page=<?php echo $page;?>&st=<?php echo $st;?>">Back</a></div>
    </td>
</tr>
</thead>

<tr>
	<td align="right" width="250">Store</td>
    <td align="left"><input class="text" name="store" type="text" value="<?php echo $q["store"];?>"/></td>
</tr>
<tr>
	<td align="right" width="250">Store Url</td>
    <td align="left"><input class="text" name="url" type="text" value="<?php echo $q["store_url"];?>"/></td>
</tr>
<tr>
	<td align="right" width="250">Gadget</td>
    <td align="left">
     <select name="gad" id="gad" class="txtborder" style="width:220px;">
    <?php 
	
	
$ads=mysql_query("select * from gadget where active_status='1' order by gadget_id ASC");
while($tech=mysql_fetch_array($ads)){
		
	?>
    <option <?php if($q ['gadget']==$tech['gadget_id']){echo "selected";}?> value="<?php echo $tech['gadget_id']?>">
	<?php echo $tech['gadget_name']?></option>
    <?php }?>
    </select>
    </td>
</tr>
<tr>
	<td align="right" width="250">Make</td>
    <td align="left"><input class="text" name="make" type="text" value="<?php echo $q["make"];?>"/></td>
</tr
><tr>
	<td align="right" width="250">Specifications</td>
    <td align="left">
    <textarea name="maincont" id="maincont" class="textarea" cols="45" rows="8"><?php echo stripslashes($q["specifications"]);?></textarea>
        <script type="text/javascript">CKEDITOR.replace( 'maincont',{skin : 'kama'});</script>
    
    </td>
</tr>
<tr>
	<td align="right" width="250">Price</td>
    <td align="left"><input class="text" name="price" type="text"  value="<?php echo $q["price"];?>"/></td>
</tr>

<tr>
	<td align="right" width="250">Image</td>
    <td align="left"><input class="text" name="upload" type="file"/><div style="display:inline; margin-left:25px;"><img src="../uploads/gadget_images/<?php echo $q["image"];?>" width="60px"  /></div> 
    
    </td>
</tr>
<tr>
	<td align="right" width="250">Sale Flag</td>
    <td align="left"><input class="text" name="flag" type="text"  value="<?php echo $q["sale_flag"];?>"/></td>
</tr
><tr>
	<td align="right" width="150">Status</td>
    <td colspan="2" align="left">
    	<select name="status">
        	<option value="0" <?php if($q["active_status"]==0) echo "selected";?>>Pending</option>
            <option value="1" <?php if($q["active_status"]==1) echo "selected";?>>Approved</option>
       	</select>     
    </td> 
</tr>

<tr>
	<td colspan="3" style="padding-left:250px;">
    	<input type="submit" value="Update" >&nbsp;&nbsp;
    </td>
</tr>        
 
</table>
</form>